package com.ruyuan.common.model;

import lombok.Data;

import java.io.Serializable;

/**
 * @author xx
 */
@Data
public class Response<T> implements Serializable {
    private static final long serialVersionUID = 2325329839653329110L;

    private boolean success;

    private T data;

    private ErrorCode errorCode;

    public static <T> Response<T> success(T data) {
        Response<T> response = new Response<>();
        response.data = data;
        response.success = true;
        return response;
    }

    public static <T> Response<T> emptySuccess(T data) {
        Response<T> response = new Response<>();
        response.success = true;
        return response;
    }

    public static <T> Response<T> fail(ErrorCode code) {
        Response<T> response = new Response<>();
        response.success = false;
        response.errorCode = code;
        return response;
    }

}
